package com.jie.demo.base;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javax.xml.ws.Response;
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.Matchers.hasProperty;
import static org.mockito.Matchers.startsWith;

/**
 * 异常测试
 */
public class BaseException {

    /**
     * 简单的异常测试
     */
    @Test(expected = IndexOutOfBoundsException.class)
    public void empty() {
        new ArrayList<Object>().get(0);
    }

    /**
     * 深度异常测试
     */
    @Rule
    public ExpectedException thrown = ExpectedException.none();

    //@Test
    public void shouldTestExceptionMessage() throws IndexOutOfBoundsException {
        List<Object> list = new ArrayList<Object>();
        // 设置期待的异常类
        thrown.expect(IndexOutOfBoundsException.class);
        // 设置期待的异常信息
        thrown.expectMessage("Index: 0, Size: 0 1");
        list.get(0); // execution will never get past this line
    }

}
